﻿#include "forceview.h"
#include "ui_forceview.h"
#include <QDebug>

forceview* forceview::_force=nullptr;

forceview::forceview(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::forceview)
{
    ui->setupUi(this);
    calibration_data={0,0,0,0,0,0};
}

forceview::~forceview()
{
    delete ui;
}

forceview *forceview::Instance()
{
    if(forceview::_force==nullptr)
    {
        _force=new forceview();
    }
    return _force;
}

void forceview::setValues(std::vector<double> value)
{
    if(value.size()<6)
    {
        //qDebug()<< "value size error";
        return;
    }

    ui->doubleSpinBox_fj1->setValue(value.at(0)-calibration_data.at(0));
    ui->doubleSpinBox_fj2->setValue(value.at(1)-calibration_data.at(1));
    ui->doubleSpinBox_fj3->setValue(value.at(2)-calibration_data.at(2));
    ui->doubleSpinBox_fj4->setValue(value.at(3)-calibration_data.at(3));
    ui->doubleSpinBox_fj5->setValue(value.at(4)-calibration_data.at(4));
    ui->doubleSpinBox_fj6->setValue(value.at(5)-calibration_data.at(5));

}

void forceview::setvalue(int i, double value)
{

}

double forceview::Getvalue(int i)
{
    double vl=0;
    switch (i) {
    case 0:
        vl=ui->doubleSpinBox_fj1->value();
        break;
    case 1:
        vl=ui->doubleSpinBox_fj2->value();
        break;
    case 2:
        vl=ui->doubleSpinBox_fj3->value();
        break;
    case 3:
        vl=ui->doubleSpinBox_fj4->value();
        break;
    case 4:
        vl=ui->doubleSpinBox_fj5->value();
        break;
    case 5:
        vl=ui->doubleSpinBox_fj6->value();
        break;
    default:
        break;
    }
    return vl;
}

QVector<double> forceview::GetVlaues()
{
    QVector<double> vec;
    vec<<ui->doubleSpinBox_fj1->value()<<ui->doubleSpinBox_fj2->value()<<ui->doubleSpinBox_fj3->value()<<ui->doubleSpinBox_fj4->value()<<ui->doubleSpinBox_fj5->value()<<ui->doubleSpinBox_fj6->value();
    return vec;
}

void forceview::setCalibrationdata(std::vector<double> data)
{
    calibration_data=data;
}
